﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MrPP.Myth;
using GDGeek;
using MrPP.Common;
using MrPP.Tracking;
using MrPP.Helper;
using MrPP.Restful;

namespace MrPP.SerriedCabinet
{
    public class ProcessBridging : MonoBehaviour
    {

        [SerializeField]
        private Uri _uri = null;
       // [SerializeField]
       // private string _url = "http://192.168.1.108:3000/geek/A/01";
        [SerializeField]
        private VuforiaMark.Mark _mark = VuforiaMark.Mark.Mark8;
        [SerializeField]
        private SearchWindow _search;
        public SearchWindow search
        {
            get
            {
                return _search;
            }
        }
        void Start()
        {



            QRCodeManager.Instance.onRecevie += this.doQrcode;
            QRCodeManager.Instance.open();
            _search.OnInput += doScreenInput;
            _search.onSelected += doScreenSelected;

        }
        public void testScanning()
        {
          //  Debug.LogError("!!!");
            //
            doQrcode(_uri.value);
          //  doAnchor(AnchorTest.Instance.transform);
        }

       
        void OnDetory()
        {
            TrackingHandler handler = this.gameObject.AskComponent<TrackingHandler>();
            GameObject.DestroyImmediate(handler);
            QRCodeManager.Instance.close();
            QRCodeManager.Instance.onRecevie -= this.doQrcode;
            _search.OnInput -= doScreenInput;
            _search.onSelected -= doScreenSelected;

        }
     
        public void doQrcode(string url)
        {
            _uri.value = url;
            Bridge.Instance.post(WindowProcess.Instance.handle, "qrcode", _uri.value);
        }


        public void doVentilate()
        {
            Bridge.Instance.post(WindowProcess.Instance.handle, "ventilate");
            //MrPP.MVC.PostToServer.Instance.post("ventilate");

        }

        public void doStop()
        {

            Bridge.Instance.post(WindowProcess.Instance.handle, "stop");
            // MrPP.MVC.PostToServer.WindowProcess.post("stop");
        }
        public void doClose()
        {

            Bridge.Instance.post(WindowProcess.Instance.handle, "close");
            //MrPP.MVC.PostToServer.Instance.post("close");
        }

        public void doOpen()
        {
            Bridge.Instance.post(WindowProcess.Instance.handle, "open");
            //MrPP.MVC.PostToServer.Instance.post("open");
        }
        private void doScreenSelected(int id)
        {
            //  SerriedCabinetPost.Instance.doScreenSelected(id);

            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_selected", id);
           // MrPP.MVC.PostToServer.Instance.post("screen_selected", id);
        }

  

        public void doSelect(IntId id)
        {
            Bridge.Instance.post(WindowProcess.Instance.handle, "select", id.value);
            //MrPP.MVC.PostToServer.Instance.post("select", id.value);

        }
      
        public void doOpenSecond(int id)
        {
            //    Debug.LogError("open:" + id);
            Bridge.Instance.post(SearchProcess.Instance.handle, "open_second", id);
            //MrPP.MVC.PostToServer.Instance.post("open_second", id);
        }
        public void doScreenGuide()
        {
            Debug.LogError("!!! guide");
            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_guide");
            //MrPP.MVC.PostToServer.Instance.post("screen_guide");
        }
        public void doScreenClear()
        {
            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_clear");
            //MrPP.MVC.PostToServer.Instance.post("screen_clear");
        }
        public void addLetter(string letter)
        {
            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_add_letter", letter);
            //MrPP.MVC.PostToServer.Instance.post("screen_add_letter", letter);
        }
        public void doScreenInput(string input)
        {

            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_input", input);
           // MrPP.MVC.PostToServer.Instance.post("screen_input", input);
        }
        public void doScreenSearch()
        {
            Bridge.Instance.post(SearchProcess.Instance.handle, "screen_search");
        }

       
    }
}